﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace YATC
{
    public class Piece
    {
        private List<Vector2> list;
        private int xOrigin = 5;
        private int yOrigin = 0;
        private int np,cp;
        private Random rand;
        private bool caro;

        public Piece()
        {
            list = new List<Vector2>();
            rand = new Random();
            np = rand.Next(7);
            GenerateNewBlock();
            
        }
        public List<Vector2> List
        {
            get { return list; }
            set { list = value; }
        }
        public int GetNextPiece()
        {
            return np;
        }
        public void GenerateNewBlock()
        {
            cp = np;
            np = rand.Next(7);

            switch (cp)   
            {
                case 0:
                    Shape1();
                    caro = true;
                    break;
                case 1:
                    Shape2();
                    caro = false;
                    break;
                case 2:
                    Shape3();
                    caro = false;
                    break;
                case 3:
                    Shape4();
                    caro = false;
                    break;
                case 4:
                    Shape5();
                    caro = false;
                    break;
                case 5:
                    Shape6();
                    caro = false;
                    break;
                case 6:
                    Shape7();
                    caro = false;
                    break;
            }
        }
        public bool Caro
        {
            get { return caro; }   
        }
        private void Shape1()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.X++;
            list.Add(tmp);
            tmp.Y++;
            list.Add(tmp);
            tmp.X = xOrigin;
            list.Add(tmp);

        }
        private void Shape2()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.X = xOrigin - 1;
            list.Add(tmp);
            tmp.X = xOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin;
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
        }
        private void Shape3()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.X = xOrigin + 1;
            list.Add(tmp);
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin;
            tmp.Y = yOrigin - 1;
            list.Add(tmp);
        }
        private void Shape4()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
            tmp.Y = yOrigin - 2;
            list.Add(tmp);
            tmp.Y = yOrigin - 1;
            list.Add(tmp);

        }
        private void Shape5()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.X = xOrigin - 1;
            list.Add(tmp);
            tmp.X = xOrigin - 1;
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin;
            tmp.Y = yOrigin - 1;
            list.Add(tmp);
        }
        private void Shape6()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin + 2;
            list.Add(tmp);
        }
        private void Shape7()
        {
            list.Clear();
            var tmp = new Vector2(xOrigin, yOrigin);
            list.Add(tmp);
            tmp.Y = yOrigin + 1;
            list.Add(tmp);
            tmp.X = xOrigin - 1;
            list.Add(tmp);
            tmp.X = xOrigin - 2;
            list.Add(tmp);
        }
    }
}
